package lumis.service.portalmanagement.channeltemplate;

import lumis.doui.source.ISourceData;
import lumis.doui.table.TableDataProvider;
import lumis.doui.table.TableSource;
import lumis.portal.PortalException;
import lumis.portal.authentication.SessionConfig;
import lumis.portal.manager.ManagerFactory;
import lumis.util.ITransaction;

import java.util.List;

/**
 * Channels path data provider.
 *
 * @version $Revision: 13092 $ $Date: 2011-05-28 18:19:06 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
public class ChannelPathDataProvider extends TableDataProvider
{
	public ChannelPathDataProvider() throws Exception
	{
		super();
	}
	
	@Override
	public void loadData(SessionConfig sessionConfig, TableSource source, ITransaction transaction) throws PortalException
	{
		super.loadData(sessionConfig, source, transaction);

		List<ISourceData> rows = source.getData().getRows();
		for(ISourceData row: rows)
		{
			String channelId = row.get("channelId", String.class);
			String channelPath = ManagerFactory.getChannelManager().getPath(sessionConfig, channelId, transaction);
			row.put("channelPath", channelPath);
		}
		
		// apply post load processing
		source.getData().sort(source);
	}
}
